package cn.ekgc.carddemo.controller;
import cn.ekgc.carddemo.entity.Pagination;
import cn.ekgc.carddemo.entity.Student;
import cn.ekgc.carddemo.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/student")
public class StudentController {
    @Autowired
    private StudentService studentService;
    @PostMapping("/save")
    @ResponseBody
    public Student save(@RequestBody Student student){
        studentService.save(student);
        return student;
    }
    @PostMapping("/list")
    @ResponseBody
    public Map<String,Object> list(@RequestBody Pagination pagination){

        return studentService.list(pagination);
    }
    @GetMapping("/sex")
    @ResponseBody
    public List<Map<String,Object>> sex(){
        List<Map<String,Object>> list = new ArrayList<>();
        Map<String,Object> data1 = new HashMap<>();
        data1.put("title","男");
        data1.put("count",100);
        Map<String,Object> data2 = new HashMap<>();
        data2.put("title","女");
        data2.put("count",45);
        list.add(data1);
        list.add(data2);
        return list;
    }
}
